home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 201-220 / scopedisk214 / req / req.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  3KB  |  105 lines

  1. /* ASL File Requester Shell for CLI Commands,
  2.   © 1991 Arnie Cachelin,  HyperActive InterMedia  */
  3. /* 24 Sep 1991 At 21:56:39 */
  4.  
  5. #include <exec/types.h>
  6. #include <exec/exec.h>
  7. #include <intuition/intuition.h>
  8. #include <libraries/dos.h>
  9. #include <libraries/asl.h>
  10. #include <workbench/startup.h>
  11. #include <workbench/workbench.h>
  12. #include <workbench/icon.h>
  13. #include <proto/intuition.h>
  14. #include <proto/exec.h>
  15. #include <proto/icon.h>
  16. /* #include <proto/asl.h> */
  17. #include <stdio.h>
  18.  
  19. struct  IntuitionBase         *IntuitionBase=NULL;
  20. struct  AslBase              *AslBase=NULL;
  21. struct  IconBase              *IconBase=NULL;
  22. struct  FileRequester          *req=NULL;
  23. extern struct   FileHandle    *Open(),*Output();
  24. extern struct   WBStartup     *WBenchMsg;
  25. struct   FileHandle    *DOSOut=NULL,*DOSIn=NULL;
  26.  
  27. void CleanUp()
  28. {
  29.     if(DOSOut) Close(DOSOut);
  30.   if(req) FreeAslRequest(req);
  31.   if(IconBase) CloseLibrary(IconBase);
  32.   if(AslBase) CloseLibrary(AslBase);
  33.   if(IntuitionBase) CloseLibrary(IntuitionBase);
  34.   exit(0L);
  35. }
  36.  
  37. int main(argc,argv)
  38.     int argc;
  39.     char    *argv[];
  40. {
  41.     char Title[82]="Hello Sailor!",Command[255],dir[80]="",*file="";
  42.   int i,n;
  43.   struct  DiskObject   *dob;
  44.  
  45.   if (argc==1)
  46.   {  /* Called w/out args from CLI  */
  47.     printf("USAGE: %s <FileCommand>\n",argv[0]);
  48.     puts("   FileCommand is the command to be executed.");
  49.     puts("   The selected path and file will replace alternating");
  50.     puts("   occurances of '%s' as in the DOS List LFORMAT command.");
  51.     puts("    ( e.g. FileReq \"C:ShowPic %s%s NOCYCLE\" ) ");
  52.     DOSOut=NULL;
  53.     CleanUp();
  54.     }
  55.   IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",0);
  56.   if (IntuitionBase==0) CleanUp();
  57.  
  58.     IconBase=(struct IconBase *) OpenLibrary("icon.library",0);
  59.   if (IconBase==0) CleanUp();
  60.  
  61.   AslBase=(struct AslBase *) OpenLibrary("asl.library",0);
  62.   if (AslBase==0) CleanUp();
  63.  
  64.     req=(struct  FileRequester *)AllocAslRequestTags(ASL_FileRequest,ASL_Hail,Title,TAG_DONE);
  65.   if (req==NULL) CleanUp();
  66.  
  67.   if(argc>1)
  68.   {  /* Called with args from CLI */
  69.       sprintf(Title,argv[1],"Dir:","File");
  70.         DOSOut = Output();
  71.     if(argc>2)
  72.       { strcpy(dir,argv[2]);
  73.         if(argc>3) file=argv[3];
  74.       }
  75.  
  76.       if (!AslRequest(req,ASL_Hail,Title,ASL_Dir,dir,ASL_File,file,TAG_END)) CleanUp();
  77.     strcpy(dir,req->rf_Dir);
  78.     n=strlen(dir);
  79.     if( n && ( (char)dir[n-1]!=':') ) strcat(dir,"/");
  80.       sprintf(Command,argv[1],dir,req->rf_File,dir,req->rf_File,dir,req->rf_File);
  81.     puts(Command);
  82.         Execute(Command,DOSIn,DOSOut);
  83.     DOSOut=NULL;
  84.     CleanUp();
  85.     }
  86.   else
  87.   if(WBenchMsg->sm_NumArgs>0)
  88.     if(dob=(struct  DiskObject *)GetDiskObject(WBenchMsg->sm_ArgList->wa_Name))
  89.     {
  90.       if(!(DOSOut = Open(FindToolType(dob->do_ToolTypes,"WINDOW"),MODE_NEWFILE)))
  91.       DOSOut = Open("CON:0/12/638/132/Command Output Window  " ,MODE_NEWFILE);
  92.         sprintf(Title,dob->do_ToolTypes[0],"Dir:","File");
  93.       if (AslRequest(req,ASL_Hail,Title,TAG_END))
  94.         for(i=0;strlen(dob->do_ToolTypes[i])>0;i++)
  95.         {
  96.              strcpy(dir,req->rf_Dir);
  97.           n=strlen(dir);     /* What a pain! why doesn't string include '/' or ':' */
  98.           if( n && ((char)dir[n-1]!=':') ) strcat(dir,"/");
  99.           sprintf(Command,dob->do_ToolTypes[i],dir,req->rf_File,dir,req->rf_File,dir,req->rf_File);
  100.           Execute(Command,DOSIn,DOSOut);
  101.            }
  102.       FreeDiskObject(dob);
  103.     }
  104.   CleanUp();
  105. }